<?php


namespace App\Http\Controllers\admin\api;


use App\Http\Controllers\admin\service\SnService;
use App\Http\Controllers\admin\validate\Sn;
use App\Http\Controllers\utils\ToolUtil;
use Illuminate\Http\Request;

class SnApi
{

    public function editTeacherSn(Request $request){
        $param = $request->all();
        $data = Sn::editTeacherSn($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::editTeacherSn($param);
    }
    
    public function queryIdBatchList(Request $request){
        $param = $request->all();
        $data = Sn::queryIdBatchList($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::queryIdBatchList($param);
    }

    public function importSnBatch(Request $request){
        $param = $request->all();
        $data = Sn::importSnBatch($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        try {
            return SnService::importSnBatch($param);
        } catch (\PHPExcel_Reader_Exception $e) {
            return ToolUtil::returnJson(400,'error1');
        } catch (\PHPExcel_Exception $e) {
            return ToolUtil::returnJson(400,'error2');
        }
    }

    public function importSn(Request $request){
        $param = $request->all();
        $data = Sn::importSn($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        try {
            return SnService::importSn($param);
        } catch (\PHPExcel_Reader_Exception $e) {
            return ToolUtil::returnJson(400,'error1');
        } catch (\PHPExcel_Exception $e) {
            return ToolUtil::returnJson(400,'error2');
        }
    }

    public function addAdminSn(Request $request){
        $param = $request->all();
        $data = Sn::addAdminSn($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::addAdminSn($param);
    }

    public function queryAdminSn(Request $request){
        $param = $request->all();
        $data = Sn::queryAdminSn($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::queryAdminSn($param);
    }

    public function deleteAdminSn(Request $request){
        $param = $request->all();
        $data = Sn::deleteAdminSn($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::deleteAdminSn($param);
    }

    public function onEmpower(Request $request){
        $param = $request->all();
        $data = Sn::onEmpower($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::onEmpower($param);
    }

    public function onBindSn(Request $request){
        $param = $request->all();
        $data = Sn::onBindSn($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::onBindSn($param);
    }

    public function singleDeviceRestartOrRecovery(Request $request){
        $param = $request->all();
        $data = Sn::singleDeviceRestartOrRecovery($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::singleDeviceRestartOrRecovery($param);
    }

    public function importUpdateSn(Request $request){
        $param = $request->all();
        $data = Sn::importUpdateSn($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::importUpdateSn($param);
    }

    public function queryBatch(Request $request){
        $param = $request->all();
        $data = Sn::queryBatch($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::queryBatch($param);
    }

    public function queryIdBatch(Request $request){
        $param = $request->all();
        $data = Sn::queryIdBatch($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::queryIdBatch($param);
    }

    public function addBatch(Request $request){
        $param = $request->all();
        $data = Sn::addBatch($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::addBatch($param);
    }

    public function editBatch(Request $request){
        $param = $request->all();
        $data = Sn::editBatch($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::editBatch($param);
    }

    public function deleteBatch(Request $request){

        $param = $request->all();
        $data = Sn::deleteBatch($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::deleteBatch($param);
    }

    public function querySnHardware(Request $request){
        $param = $request->all();
        $data = Sn::querySnHardware($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::querySnHardware($param);
    }
    
    public function cleanInstallAppCache(Request $request){
        $param = $request->all();
        $data = Sn::cleanInstallAppCache($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::cleanInstallAppCache($param);
    }

    public function renovate(Request $request){
        $param = $request->all();
        $data = Sn::renovate($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::renovate($param);
    }

    public function uninstallApp(Request $request){
        $param = $request->all();
        $data = Sn::uninstallApp($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::uninstallApp($param);
    }

    public function forceStopApp(Request $request){
        $param = $request->all();
        $data = Sn::forceStopApp($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::forceStopApp($param);
    }

    public function sendScreenshot(Request $request){
        $param = $request->all();
        $data = Sn::sendScreenshot($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::sendScreenshot($param);
    }

    public function queryScreenshot(Request $request){
        $param = $request->all();
        $data = Sn::queryScreenshot($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::queryScreenshot($param);
    }

    public function deleteScreenshot(Request $request){
        $param = $request->all();
        $data = Sn::deleteScreenshot($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::deleteScreenshot($param);
    }

    public function addParentTimeControl(Request $request){
        $param = $request->all();
        $data = Sn::addParentTimeControl($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::addParentTimeControl($param);
    }

    public function addTeacherTimeControl(Request $request){
        $param = $request->all();
        $data = Sn::addTeacherTimeControl($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::addTeacherTimeControl($param);
    }

    public function queryParentTimeControl(Request $request){
        $param = $request->all();
        $data = Sn::queryTimeControl($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        $param['status'] = 1;
        return SnService::queryTimeControl($param);
    }

    public function queryTeacherTimeControl(Request $request){
        $param = $request->all();
        $data = Sn::queryTimeControl($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        $param['status'] = 2;
        return SnService::queryTimeControl($param);
    }

    public function queryIdParentTimeControl(Request $request){
        $param = $request->all();
        $data = Sn::queryIdTimeControl($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        $param['status'] = 1;
        return SnService::queryIdTimeControl($param);
    }

    public function queryIdTeacherTimeControl(Request $request){
        $param = $request->all();
        $data = Sn::queryIdTimeControl($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        $param['status'] = 2;
        return SnService::queryIdTimeControl($param);
    }

    public function updateParentTimeControl(Request $request){
        $param = $request->all();
        $data = Sn::updateTimeControl($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        $param['status'] = 2;
        return SnService::updateTimeControl($param);
    }

    public function updateTeacherTimeControl(Request $request){
        $param = $request->all();
        $data = Sn::updateTimeControl($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        $param['status'] = 2;
        return SnService::updateTimeControl($param);
    }

    public static function deleteParentTimeControl(Request $request){
        $param = $request->all();
        $data = Sn::deleteTimeControl($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        $param['status'] = 1;
        return SnService::deleteTimeControl($param);
    }

    public static function deleteTeacherTimeControl(Request $request){
        $param = $request->all();
        $data = Sn::deleteTimeControl($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        $param['status'] = 2;
        return SnService::deleteTimeControl($param);
    }

}